<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>权限管理系统－功能管理</title>
<script type="text/javascript" src="${resurl}/js/jquery.js"></script>
<script src="${resurl}/js/bootstrap.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="${resurl}/css/bootstrap.min.css">
<link rel="stylesheet" href="${resurl}/css/common.css">
<script type="text/javascript">
	$(document).ready(
			function() {

				//删除模块
				$("button#deletefunc_btn").click(function() {
					var func_id = $("input[type='radio']:checked").val();
					$.post("${resurl}/funcdelete.pms", {
						func_id : func_id
					}, function(data, status) {
						location.reload();
					});
				});

				//新增模块
				$("button#addfunc_btn").click(function() {
					$("input#insert_inputFuncName").val("");
					$("input#insert_inputFuncLink").val("");
					$("h4#insert_modal_title").text("新增模块");
				});

				//保存模块
				$("button#modal_insertfunc_btn").click(function() {
					var funcname = $("input#insert_inputFuncName").val();
					var funclink = $("input#insert_inputFuncLink").val();
					var valid = $("select#insert_selectValid").val();
					$.post("${resurl}/funcinsert.pms", {
						func_name : funcname,
						func_link : funclink,
						func_valid : valid
					}, function(data, status) {
						location.reload();
					});
				});

				//更新模块
				$("button#updatefunc_btn").click(
						function() {
							//给修改框赋值
							var func_id = $("input[type='radio']:checked")
									.val();
							var funcname = $("table tr#" + func_id).children()
									.eq(1).text();
							var funclink = $("table tr#" + func_id).children()
									.eq(2).text();
							var valid = $("table tr#" + func_id).children().eq(
									4).text();
							$("h4#update_modal_title").text(
									"修改模块信息:" + funcname);
							$("input[type='hidden']#modal_update_func_id")
									.attr("value", func_id);
							$("input#update_inputFuncName").val(funcname);
							$("input#update_inputFuncLink").val(funclink);
							if (valid == "yes") {
								$("#modal_update_valid_yes").prop("selected",
										true);
							} else {
								$("#modal_update_valid_no").prop("selected",
										true);
							}
						});

				//更新模块
				$("button#modal_updatefunc_btn").click(function() {
					var func_id = $("input#modal_update_func_id").val();
					var funcname = $("input#update_inputFuncName").val();
					var funclink = $("input#update_inputFuncLink").val();
					var valid = $("select#update_selectValid").val();
					$.post("${resurl}/funcupdate.pms", {
						func_id : func_id,
						func_name : funcname,
						func_link : funclink,
						func_valid : valid
					}, function(data, status) {
						location.reload();
					});
				});

			});
</script>
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#navbar" aria-expanded="false"
					aria-controls="navbar">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="${resurl }/index.pms">权限管理系统</a>
			</div>
			<div id="navbar" class="navbar-collapse collapse">
				<ul class="nav navbar-nav navbar-right">
					<li><a href="#">设置</a></li>
					<li><a href="#">个人资料</a></li>
					<li><a href="#">帮助</a></li>
				</ul>
				<form class="navbar-form navbar-right">
					<input type="text" class="form-control" placeholder="查询...">
				</form>
			</div>
		</div>
	</nav>

	<div class="container-fluid">
		<div class="row">
			<div class="sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="${resurl }/index.pms">首页</a></li>
					<li><a href="${resurl}/userindex.pms">用户管理</a></li>
					<li><a href="${resurl}/deptindex.pms">部门管理</a></li>
					<li><a href="${resurl }/permindex.pms">权限管理</a></li>
					<li class="active"><a href="${resurl }/funindex.pms">功能管理<span
							class="sr-only">(current)</span></a></li>
				</ul>
			</div>
			<div class="main">
				<h2 class="sub-header">功能列表</h2>
				<div id="operator" class="navbar-collapse collapse operation">
					<ul class="nav navbar-nav navbar-right">
						<li class="li-button"><button id="addfunc_btn"
								class="btn btn-sm btn-success btn-block" type="button"
								data-toggle="modal" data-target="#addfunc_modal">新增模块</button></li>
						<li class="li-button"><button id="updatefunc_btn"
								class="btn btn-sm btn-warning btn-block" type="button"
								data-toggle="modal" data-target="#updatefunc_modal">修改模块</button></li>
						<li class="li-button"><button id="deletefunc_btn"
								class="btn btn-sm btn-danger btn-block" type="button">删除模块</button></li>
					</ul>
				</div>
				<div class="table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>选择</th>
								<th>模块名称</th>
								<th>模块链接</th>
								<th>是否有效</th>
							</tr>
						</thead>
						<tbody>

							<c:forEach items="${fnlist}" var="func" varStatus="status">
								<tr id="${func.func_id }">
									<td><input name="func_id" type="radio"
										value="${func.func_id }"></td>
									<td id="func_name">${func.func_name }</td>
									<td id="func_link">${func.func_link }</td>
									<td id="func_valid"><c:if test="${func.func_valid=='yes'}">有效</c:if>
										<c:if test="${func.func_valid=='no'}">无效</c:if></td>
									<td id="func_valid_id" style="display:none">${func.func_valid }</td>
								</tr>
							</c:forEach>

						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="addfunc_modal" tabindex="-1" role="dialog"
		aria-labelledby="addfuncModelLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 id="insert_modal_title" class="modal-title">添加新模块</h4>
				</div>
				<div class="modal-body">
					<label for="insert_inputFuncName" class="control-label">模块名称</label>
					<input name="funcname_input" type="text" id="insert_inputFuncName"
						class="form-control" placeholder="输入模块名称" required="required"
						autofocus=""> <label class="control-label">模块链接</label> <input
						name="funclink_input" type="text" id="insert_inputFuncLink"
						class="form-control" placeholder="输入模块链接" required="required"
						autofocus=""> <label for="insert_selectValid">是否有效</label>
					<select name="func_valid_select" id="insert_selectValid"
						class="form-control">
						<option value="yes" selected>生效</option>
						<option value="no">失效</option>
					</select>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<button id="modal_insertfunc_btn" type="button"
						class="btn btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>


	<div class="modal fade" id="updatefunc_modal" tabindex="-1"
		role="dialog" aria-labelledby="updatefuncModelLabel"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 id="update_modal_title" class="modal-title"></h4>
				</div>
				<div class="modal-body">
					<input id="modal_update_func_id" type="hidden" value="" /> <label
						for="update_inputFuncName">模块名称</label> <input
						name="funcname_input" type="text" id="update_inputFuncName"
						class="form-control" placeholder="输入模块名称" required="required"
						autofocus=""> <label for="update_inputFuncLink">模块链接</label>
					<input name="funclink_input" type="text" id="update_inputFuncLink"
						class="form-control" placeholder="输入模块名称" required="required"
						autofocus=""> <label for="selectValid">是否有效</label> <select
						name="user_valid_select" id="update_selectValid"
						class="form-control">
						<option id="modal_update_valid_yes" value="yes">生效</option>
						<option id="modal_update_valid_no" value="no">失效</option>
					</select>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<button id="modal_updatefunc_btn" type="button"
						class="btn btn-primary">更新</button>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
